package frank.zou.study.sample.in.persuit.of.quiality;

import java.util.ArrayList;
import java.util.List;

public class Stack<E> {

	private List<E> list = new ArrayList<E>();

	public void push(E value) {
		if (value == null) {
			throw new RuntimeException("Can't push null");
		} else {
			list.add(value);
		}
	}

	public E pop() {
		if (list.size() <= 0) {
			throw new RuntimeException("cannot pop: stack is empty.");
		} else {
			return list.remove(list.size() - 1);
		}
	}

	public E peak() {
		// TODO Auto-generated method stub
		if (list.size() > 0) {
			return list.get(list.size() - 1);
		} else {
			return null;
		}
		// return null;
	}
}
